<template>
  <div class="robot-list-container">
    <!-- 顶部导航 -->
    <van-nav-bar
        title="好友验证"
        left-arrow
        right-text="发送"
        @click-left="goBack"
        @click-right="add"
        class="nav-bar"
    />

    <div class="search-section" style="margin: 10px;" >
      <h3>发送添加好友验证</h3>
      <van-cell-group>
        <van-field
           v-model="value"
          placeholder="请输入用户名"
          :border="false"
        />
      </van-cell-group>

    </div>
  </div>
</template>

<script>
  import { postAction } from '@/api'

export default {
  name: "addfriend",
  data(){
    return{
      data:{},
      value:"",
      userInfo:{}
    }
  },
  mounted() {
  },
  created() {
    console.log(this.$route.params)
    this.data = this.$route.params;
    const userInfoString = localStorage.getItem('pro__login_user_info');
    if (userInfoString) {
      const userInfo = JSON.parse(userInfoString);
      this.userInfo = userInfo.value;
      this.value = '我是'+ this.userInfo.realname
    }
  },
  methods:{
    add(){
      postAction('/sys/chat/FriendRequest/add', {
					applicantid: this.userInfo.id,
					recipientid: this.data.id,
					content: this.value,
				}).then((res) => {
          if(res.code===200){
            this.$toast.success(res.message)
          }else{
            this.$toast.fail(res.message)
          }
          this.gosearch();
        })

    },
    goBack(){
      this.$router.go(-1);
    },
    gosearch(){
      this.$router.push({name: 'gosearch'})
    }
  }
}
</script>

<style scoped>
.robot-list-container {
  background-color: #f4f8f9;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/deep/ .van-search{
  border-radius: 6px;
  padding: 5px 5px;
}
/deep/ .van-search__content{
  background-color: white !important;
  padding-left:0px !important;
}
</style>
